phpstan: variable.implicitArray#5551
Conversation
There was a problem hiding this comment.
Pull request overview
This PR applies minor PHPStan-driven fixes by eliminating implicit array creation and a few related baseline suppressions across core, lib, and template code.
Changes:
- Initialize variables as arrays before assigning offsets to satisfy
variable.implicitArray. - Harden
Varien_Object::_addFullNames()against non-array_datato avoid invalid array operations. - Remove PHPStan baseline entries/files that are no longer needed after the fixes (including class name case ignore).
Reviewed changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| lib/Varien/Object.php | Adds array-type guards before sync-field mapping to avoid invalid array operations. |
| lib/Varien/Io/File.php | Initializes $owner/$group/$world arrays before offset assignment in permission parsing. |
| app/design/frontend/base/default/template/paypal/payment/redirect.phtml | Updates docblock class references to correct case used in codebase and removes related baseline need. |
| app/code/core/Mage/Sales/Model/Order/Pdf/Shipment.php | Initializes $lines before nested offset usage in header rendering. |
| app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php | Initializes $lines before nested offset usage in header rendering. |
| app/code/core/Mage/Sales/Model/Order/Pdf/Creditmemo.php | Initializes $lines before nested offset usage in header rendering. |
| app/code/core/Mage/Paygate/controllers/Authorizenet/PaymentController.php | Initializes $result before setting result keys in cancel action. |
| app/code/core/Mage/Paygate/controllers/Adminhtml/Paygate/Authorizenet/PaymentController.php | Initializes $result before setting result keys in cancel action. |
| app/code/core/Mage/Page/Block/Html/Toplinks.php | Initializes $toplinkInfo before populating it. |
| app/code/core/Mage/Newsletter/Model/Resource/Subscriber.php | Initializes $data before populating update payload. |
| app/code/core/Mage/Downloadable/Model/Resource/Link.php | Initializes $dataToInsert before population. |
| app/code/core/Mage/CurrencySymbol/Model/System/Currencysymbol.php | Initializes $value before writing nested option structure. |
| app/code/core/Mage/Core/Model/File/Validator/AvailablePath.php | Initializes $options before setting file_mask. |
| app/code/core/Mage/Cms/Model/Resource/Page/Collection.php | Initializes $data before setting value/label. |
| app/code/core/Mage/Checkout/controllers/OnepageController.php | Initializes $result early for consistent array usage. |
| app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Minimalprice.php | Initializes $conditions before appending SQL conditions. |
| app/code/core/Mage/CatalogIndex/Model/Resource/Indexer/Abstract.php | Initializes $conditions before appending SQL conditions. |
| app/code/core/Mage/CatalogIndex/Model/Indexer/Minimalprice.php | Initializes $data and $search arrays before offset assignment. |
| app/code/core/Mage/Catalog/Model/Resource/Product.php | Initializes $updateCond before appending conditions. |
| app/code/core/Mage/Catalog/Model/Product/Image.php | Initializes $path prior to usage to satisfy PHPStan (see review nit). |
| app/code/core/Mage/Catalog/Model/Layer/Filter/Item.php | Initializes $params before setting URL generation flags. |
| app/code/core/Mage/Catalog/Block/Layer/State.php | Initializes $params before setting URL generation flags. |
| app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle.php | Ensures $defaultValues is always defined and reorders a couple initializations. |
| app/code/core/Mage/Adminhtml/controllers/TagController.php | Initializes $data before offset assignment; tightens return docblock. |
| app/code/core/Mage/Adminhtml/controllers/Catalog/CategoryController.php | Initializes $params before use. |
| app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/View/Form.php | Initializes $data before building URL params. |
| app/code/core/Mage/Adminhtml/Block/Sales/Order/Shipment/Packaging.php | Initializes $data before building URL params; removes stray whitespace line. |
| app/code/core/Mage/Adminhtml/Block/Newsletter/Template/Grid/Renderer/Action.php | Initializes $actions before conditional pushes. |
| app/code/core/Mage/Adminhtml/Block/Catalog/Helper/Form/Wysiwyg/Content.php | Initializes $config before nested offset assignment. |
| .phpstan.dist.baselines/variable.undefined.php | Removes baseline entry now fixed in bundle JSON config logic. |
| .phpstan.dist.baselines/variable.implicitArray.php | Removes many no-longer-needed ignores after explicit array initialization. |
| .phpstan.dist.baselines/offsetAccess.notFound.php | Removes baseline entry now handled by guards in Varien_Object. |
| .phpstan.dist.baselines/empty.notAllowed.php | Updates ignore count after reducing one empty() usage. |
| .phpstan.dist.baselines/class.nameCase.php | Removes obsolete baseline file (now fixed in template docblock). |
| .phpstan.dist.baselines/argument.type.php | Removes obsolete baseline entry after guarding array usage in Varien_Object. |
| .phpstan.dist.baselines/_loader.php | Stops loading the removed class.nameCase baseline file. |
| $params = []; | ||
| $params['_current'] = true; | ||
| $params['_use_rewrite'] = true; | ||
| $params['_query'] = $filterState; | ||
| $params['_escape'] = true; | ||
|
|
There was a problem hiding this comment.
Wouldn't it be better to have $params = [ ... ]?
with [ ... ] being a Multiline Array?
Or better return Mage::getUrl('*/*/*', [ ... ]);
There was a problem hiding this comment.
I think this will be to much work.
Lets keep it simple.
There was a problem hiding this comment.
@sreichel i meant to write the params array like this:
$params = [
'_current' => true,
'_use_rewrite' => true,
'_query' => $filterState,
'_escape' => true,
];or like this:
return Mage::getUrl('*/*/*', [
'_current' => true,
'_use_rewrite' => true,
'_query' => $filterState,
'_escape' => true,
]);i found a rector for similar stuff, but not quite the right thing:
https://getrector.com/rule-detail/inline-array-return-assign-rector
Edit: i asked if there is an extra rule: rectorphp/rector#9747
there isn't one right now
There was a problem hiding this comment.
Yeah, to automate it, but atm i dont wont to spent much time for writing rules.
(there should be some project/OM-related rules first e.g. change to getDataById())
btw ... we also have CodeSniffer/Beatifier, cs-fixer with additional ECS rules, but no one covers this
|


Description (*)
Minor phpstan fixes.